home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * Simple Sample PowerTalk Application Framework
- *
- * ©1991-1993 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * windutils.c -- window drawing/scrolling utility functions
- *
- * change history:
- *
- * SJF 08/23/93 1.0f1 update to final headers, fix comments
- * SJF 04/21/93 1.0b2 update to b2
- * SJF 03/01/93 1.0b1 added digital signatures
- * SJF 02/09/93 1.0b1 update to b1
- * SJF 10/13/92 1.0d4 update to a11
- * SJF 09/09/92 1.0d3 update to a9
- * SJF 05/07/92 1.0d2 update to a6
- * SJF 11/06/91 1.0d1 initial coding
- *
- */
-
- #pragma segment othersegment
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __OCESTANDARDMAIL__
- #include <OCEStandardMail.h>
- #endif
-
- #include "const.h"
- #include "strconst.h"
- #include "mytypes.h"
- #include "globals.h"
- #include "utils.h"
- #include "windowstuff.h"
- #include "mystandardmail.h"
- #include "draw.window.h"
-
- #include "windutils.h"
-
-
- /* clips out all of the window except the grow icon location to draw the grow icon */
- /* this is to avoid the problem caused when you have a window crossing a B&W and a color screen */
-
- void MyDrawGrowIcon(WindowPtr window)
- {
- GrafPtr savePort;
- RgnHandle saveClip;
- Rect gbRect;
-
- gbRect = window->portRect;
- gbRect.top = gbRect.bottom - kGrowBoxWidth;
- gbRect.left = gbRect.right - kGrowBoxWidth;
- GetPort(&savePort);
- SetPort(window);
-
- saveClip = NewRgn();
- GetClip(saveClip);
- ClipRect(&gbRect);
-
- DrawGrowIcon(window);
-
- SetClip(saveClip);
- DisposeRgn(saveClip);
-
- SetPort(savePort);
- }
-
-
- /* clip the window to just the drawing area */
-
- void ClipToDrawing(WindowPtr window,WInfoPtr infoPtr)
- {
- Rect newClipRect;
-
- newClipRect = window->portRect;
- newClipRect.top += infoPtr->topIndent;
- newClipRect.left += infoPtr->leftIndent;
- ClipRect(&newClipRect);
- }
-
-
- /* get the region containing the scroll bars */
-
- RgnHandle GetScrollersRgn(Rect *windowRect)
- {
- RgnHandle windowRgn;
- Rect wRect;
-
- windowRgn = NewRgn();
-
- OpenRgn();
- SetRect(&wRect,windowRect->left,windowRect->bottom-kScrollBarWidth,
- windowRect->right-kScrollBarWidth,windowRect->bottom);
- FrameRect(&wRect);
- SetRect(&wRect,windowRect->right-kScrollBarWidth,windowRect->top,
- windowRect->right,windowRect->bottom);
- FrameRect(&wRect);
- CloseRgn(windowRgn);
-
- return windowRgn;
- }
-
-
- /* make our scroll bars */
-
- void MakeScrollBars(WindowPtr window,WInfoPtr infoPtr)
- {
- GrafPtr savePort;
- Rect cntrlRect;
-
- infoPtr->otherData[kViewOffset] = 0;
-
- GetPort(&savePort);
- SetPort(window);
-
- cntrlRect.left += infoPtr->leftIndent;
- cntrlRect = window->portRect;
- InsetRect(&cntrlRect,-1,-1);
- cntrlRect.top = cntrlRect.bottom - kScrollBarWidth;
- cntrlRect.right = cntrlRect.right - kGrowBoxWidth;
- HSCROLL = NewControl(window,&cntrlRect,"\p",false,0,0,0,scrollBarProc,0);
- ValidRect(&cntrlRect);
-
- cntrlRect = window->portRect;
- InsetRect(&cntrlRect,-1,-1);
- cntrlRect.left = cntrlRect.right - kScrollBarWidth;
- cntrlRect.bottom = cntrlRect.bottom - kGrowBoxWidth;
- cntrlRect.top += infoPtr->topIndent;
- VSCROLL = NewControl(window,&cntrlRect,"\p",false,0,0,0,scrollBarProc,0);
- ValidRect(&cntrlRect);
-
- ReCalcScrollBars(window,infoPtr);
- ShowControl((ControlHandle)HSCROLL);
- ShowControl((ControlHandle)VSCROLL);
-
- SetPort(savePort);
- }
-
-
- /* move the scroll bars when the window moves */
-
- void MoveScrollBars(WindowPtr window)
- {
- WInfoPtr infoPtr;
- char hState;
- Rect cntrlRect;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(window);
-
- infoPtr = BeginWindowAccess(window,&hState);
-
- HideControl((ControlHandle)VSCROLL);
- HideControl((ControlHandle)HSCROLL);
-
- if (infoPtr->topIndent<=(window->portRect.bottom-kGrowBoxWidth) &&
- infoPtr->leftIndent<=(window->portRect.right-kGrowBoxWidth)) {
-
- cntrlRect = window->portRect;
- InsetRect(&cntrlRect,-1,-1);
- cntrlRect.top = cntrlRect.bottom - kScrollBarWidth;
- cntrlRect.right = cntrlRect.right - kGrowBoxWidth;
- cntrlRect.left += infoPtr->leftIndent;
- MoveControl(HSCROLL,cntrlRect.left,cntrlRect.top);
- SizeControl(HSCROLL,cntrlRect.right-cntrlRect.left,cntrlRect.bottom-cntrlRect.top);
- ValidRect(&cntrlRect);
-
- cntrlRect = window->portRect;
- InsetRect(&cntrlRect,-1,-1);
- cntrlRect.left = cntrlRect.right - kScrollBarWidth;
- cntrlRect.bottom = cntrlRect.bottom - kGrowBoxWidth;
- cntrlRect.top += infoPtr->topIndent;
- MoveControl(VSCROLL,cntrlRect.left,cntrlRect.top);
- SizeControl(VSCROLL,cntrlRect.right-cntrlRect.left,cntrlRect.bottom-cntrlRect.top);
- ValidRect(&cntrlRect);
-
- ReCalcScrollBars(window,infoPtr);
-
- ShowControl(HSCROLL);
- ShowControl(VSCROLL);
-
- }
-
- EndWindowAccess(window,hState);
- SetPort(savePort);
- }
-
-
- /* recalculate the scroll bars when the window changes */
-
- void ReCalcScrollBars(WindowPtr window,WInfoPtr infoPtr)
- {
- Rect viewBounds,pageRect;
- short vMax,hMax;
- Point *scrollPos;
-
- GetViewBounds(window,infoPtr,&viewBounds);
- pageRect = (**(infoPtr->printRecord)).prInfo.rPage;
- scrollPos = (Point *)&infoPtr->otherData[kViewOffset];
-
- hMax = (pageRect.right-pageRect.left) - (viewBounds.right-viewBounds.left);
- vMax = (pageRect.bottom-pageRect.top) - (viewBounds.bottom-viewBounds.top);
-
- if (hMax<0)
- hMax=0;
- if (vMax<0)
- vMax=0;
-
- if ( (scrollPos->h+(viewBounds.right-viewBounds.left)) > (pageRect.right-pageRect.left) )
- scrollPos->h = (pageRect.right-pageRect.left) - (viewBounds.right-viewBounds.left);
- if ( (scrollPos->v+(viewBounds.bottom-viewBounds.top)) > (pageRect.bottom-pageRect.top) )
- scrollPos->v = (pageRect.bottom-pageRect.top) - (viewBounds.bottom-viewBounds.top);
-
- SetCtlMax((ControlHandle)HSCROLL,hMax);
- SetCtlMax((ControlHandle)VSCROLL,vMax);
- SetCtlValue((ControlHandle)HSCROLL,scrollPos->h);
- SetCtlValue((ControlHandle)VSCROLL,scrollPos->v);
- SetPort(window);
- }
-
-
- /* action callback to scroll the document */
-
- pascal void ScrollActionProc(ControlHandle theControl,short part)
- {
- short ctlValue,delta,ctlMin,ctlMax,pageDistance,deltaH,deltaV;
- Rect viewRect;
- WindowPtr window;
- WInfoPtr infoPtr;
- char hState;
-
- if (part==0)
- return;
-
- window = (**theControl).contrlOwner;
- if (!IsAppWindow(window))
- return;
-
- infoPtr = BeginWindowAccess(window,&hState);
-
- GetViewBounds(window,infoPtr,&viewRect);
- pageDistance = viewRect.bottom-viewRect.top;
-
- ctlValue = GetCtlValue(theControl);
- ctlMin = GetCtlMin(theControl);
- ctlMax = GetCtlMax(theControl);
-
- switch (part) {
- case inUpButton:
- delta = -kScrollDistance;
- break;
- case inDownButton:
- delta = kScrollDistance;
- break;
- case inPageUp:
- delta = -pageDistance;
- break;
- case inPageDown:
- delta = pageDistance;
- break;
- }
-
- if ( (ctlValue+delta)>ctlMax )
- delta = ctlMax-ctlValue;
- else if ( (ctlValue+delta)<ctlMin )
- delta = ctlMin-ctlValue;
-
- SetCtlValue(theControl,ctlValue+delta);
-
- deltaH = deltaV = 0;
- if (theControl==(ControlHandle)HSCROLL)
- deltaH = delta;
- else if (theControl==(ControlHandle)VSCROLL)
- deltaV = delta;
-
- MoveGraphics(window,infoPtr,deltaH,deltaV);
-
- EndWindowAccess(window,hState);
- }
-
-
- /* move the shapes in the window */
-
- void MoveGraphics(WindowPtr window,WInfoPtr infoPtr,short deltaH,short deltaV)
- {
- GrafPtr savePort;
- Rect drawingArea;
- RgnHandle updateRgn,saveClip;
- Point *scrollPos,drawOffset;
-
- GetDrawingAreaBounds(window,infoPtr,&drawingArea);
-
- // store new scroll position into window data
-
- scrollPos = (Point *)&infoPtr->otherData[kViewOffset];
- scrollPos->h += deltaH;
- scrollPos->v += deltaV;
-
- drawOffset = *scrollPos;
- drawOffset.h = infoPtr->leftIndent-drawOffset.h;
- drawOffset.v = infoPtr->topIndent-drawOffset.v;
-
- // do drawing of scrolling
-
- GetPort(&savePort);
- SetPort(window);
- updateRgn = NewRgn();
- saveClip = NewRgn();
- ScrollRect(&drawingArea,-deltaH,-deltaV,updateRgn);
- GetClip(saveClip);
- SetClip(updateRgn);
- DrawAllShapes(infoPtr,drawOffset);
- SetClip(saveClip);
- DisposeRgn(updateRgn);
- DisposeRgn(saveClip);
- SetPort(savePort);
- }
-
-
- /* check to make sure we're not bigger than our print area */
-
- Boolean CheckPageSize(WindowPtr window,WInfoPtr infoPtr)
- {
- Rect oldSize;
- short newWidth,newHeight,oldWidth,oldHeight;
- GrafPtr savePort;
- Boolean changed;
-
- ClipPageSize(&window->portRect,infoPtr,&newWidth,&newHeight);
- oldWidth = window->portRect.right-window->portRect.left;
- oldHeight = window->portRect.bottom-window->portRect.top;
-
- // force a new window size on the user since they changed page setup on us
-
- if (newHeight!=oldHeight || newWidth!=oldWidth) {
- GetPort(&savePort);
- SetPort(window);
- oldSize = window->portRect;
- SizeWindow(window,newWidth,newHeight,true);
- InvalRect(&window->portRect);
- SendWindowMessage(window,kResizeMessage,&oldSize);
- SetPort(savePort);
- changed = true;
- }
- else
- changed = false;
-
- return changed;
- }
-
-
- /* make our drawing only as big as our print area */
-
- void ClipPageSize(Rect *wRect,WInfoPtr infoPtr,short *maxWidth,short *maxHeight)
- {
- Rect printRect,drawAreaRect;
-
- printRect = (**(infoPtr->printRecord)).prInfo.rPage;
-
- drawAreaRect.top = infoPtr->topIndent;
- drawAreaRect.left = infoPtr->leftIndent;
- drawAreaRect.bottom = wRect->bottom-wRect->top-kScrollBarWidth;
- drawAreaRect.right = wRect->right-wRect->left-kScrollBarWidth;
-
- *maxWidth = wRect->right-wRect->left;
- *maxHeight = wRect->bottom-wRect->top;
- if ( (drawAreaRect.right-drawAreaRect.left) > (printRect.right-printRect.left) )
- *maxWidth = (printRect.right-printRect.left)+infoPtr->leftIndent+kScrollBarWidth;
- if ( (drawAreaRect.bottom-drawAreaRect.top) > (printRect.bottom-printRect.top) )
- *maxHeight = (printRect.bottom-printRect.top)+infoPtr->topIndent+kScrollBarWidth;
- }
-
-
- /* get the bounds of the view that we can see */
-
- void GetViewBounds(WindowPtr window,WInfoPtr infoPtr,Rect *bounds)
- {
- Point viewOffset;
-
- viewOffset = *(Point *)&infoPtr->otherData[kViewOffset];
- GetDrawingAreaBounds(window,infoPtr,bounds);
- OffsetRect(bounds,-infoPtr->topIndent,-infoPtr->leftIndent);
- OffsetRect(bounds,viewOffset.h,viewOffset.v);
- }
-
-
- /* get the bounds of the drawing that we can see */
-
- void GetDrawingAreaBounds(WindowPtr window,WInfoPtr infoPtr,Rect *bounds)
- {
- bounds->top = infoPtr->topIndent;
- bounds->left = infoPtr->leftIndent;
- bounds->bottom = window->portRect.bottom-window->portRect.top-kScrollBarWidth;
- bounds->right = window->portRect.right-window->portRect.left-kScrollBarWidth;
- }
-
-
-